//
//  LKCaseModel.m
//  QuickCure
//
//  Created by 胡不归是大虾 on 9/13/16.
//  Copyright © 2016 haoge. All rights reserved.
//

#import "LKCaseModel.h"
#import "NSObject+Coding.h"
#import <objc/runtime.h>
@implementation LKCaseModel
//编码
-(void)encodeWithCoder:(NSCoder *)aCoder
{
//    //获取一个类的所有属性
//   unsigned int outCount = 0;
//    Ivar * ivars = class_copyIvarList([self class], &outCount) ;
//
//    //遍历所有属性
//    for (int i = 0; i < outCount; i++) {
//        //取出属性
//        Ivar ivar = ivars[i];
//        //拿到属性名
//        const char* name = ivar_getName(ivar);
//        NSString* InstanceName = [NSString stringWithUTF8String:name];
//        //通过属性名拿到属性的值
//        id value = [self valueForKey:InstanceName];
//        //归档
//        [aCoder encodeObject:value forKey:InstanceName];
//    }
//    free(ivars);
//    [aCoder encodeObject:_caseImage forKey:@"caseImage"];
//    [aCoder encodeObject:_illnessTypeStr forKey:@"illnessType"];
//    [aCoder encodeObject:_basicTypeStr forKey:@"basicTypeStr"];
//    [aCoder encodeObject:_illnessDescStr forKey:@"illnessDescStr"];
//    [aCoder encodeObject:_commitTime forKey:@"commitTime"];
    [self encode:aCoder];
}
//解码
-(instancetype)initWithCoder:(NSCoder *)aDecoder
{
    if (self = [super init]) {
        [self decode:aDecoder];
        //拿到所有属性
//        unsigned int outCount = 0 ;
//        Ivar* ivars = class_copyIvarList([self class], &outCount);
//        //遍历
//        for (int i = 0; i < outCount; i++) {
//            Ivar ivar = ivars[i];
//            //拿到属性名
//            NSString* key = [NSString stringWithUTF8String:ivar_getName(ivar)];
//            //解档赋值
//            id value = [aDecoder decodeObjectForKey:key];
//            [self setValue:value forKey:key];
//        }
//        free(ivars);
//        self.caseImage = [aDecoder decodeObjectForKey:@"caseImage"];
//        self.illnessTypeStr = [aDecoder decodeObjectForKey:@"illnessType"];
//        self.illnessDescStr = [aDecoder decodeObjectForKey:@"illnessDescStr"];
//        self.basicTypeStr = [aDecoder decodeObjectForKey:@"basicTypeStr"];
//        self.commitTime = [aDecoder decodeObjectForKey:@"commitTime"];
    }
    return self;
}

@end
